package com.cg.bio.case02;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 多发和多收
 */
public class Client {

    public static void main(String[] args) throws IOException {
        //创建socket对象请求服务端的连接
        Socket socket = new Socket("127.0.0.1", 9999);
        //从socket对象中获取一个字节输出流
        OutputStream outputStream = socket.getOutputStream();
        //把字节输出流包装成一个打印流
        PrintStream printStream = new PrintStream(outputStream);
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请发送消息...");
            String msg = scanner.nextLine();
            printStream.println(msg);
            printStream.flush();
        }
    }

}
